package innerclassdemo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: XMQ
 * Date: 2022-05-13
 * Time: 15:02
 */
//内部类
//class OutClass{
//    public int data1 = 1;
//    private int data2 = 2;
//    public static int data3 = 3;
//
//    public OutClass(){
//        System.out.println("OutClass的构造方法！");
//    }
//    /*
//        1.不能定义静态的属性或方法
//        2.实例内部类中包含了外部类的this
//        3.获取实例类内部类的对象
//        4.生成的字节码文件：外部类$内部类
//    */
//    class InnerClass{
//        public int data1 = 4;
//        private int data5 = 5;
//        public static final int data6 = 6;
//
//        public InnerClass(){
//            System.out.println("InnerClass的构造方法！");
//        }
//        public void func(){
//            System.out.println(this.data1);
//            System.out.println(OutClass.this.data1);
//            System.out.println(data3);
//        }
//    }
//
//}
class OutClass{
    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;
    /*
        静态内部类:
        1.如何拿到静态内部类的对象呢
        2.不能在静态内部类当中，直接访问外部类非静态的成员
     */
    static class InnerClass{
        public int data4 = 4;
        private int data5 = 5;
        public static int data6 = 6;
        public OutClass out;

        public InnerClass(OutClass out){
            System.out.println("静态内部类的构造方法");
            this.out = out;
        }
        public void test(){
//            OutClass out = new OutClass();
            System.out.println(1);
            System.out.println(out.data1);
            System.out.println(out.data2);
            System.out.println(data3);
            System.out.println(data4);
        }
    }

    @Override
    public String toString() {
        return "OutClass{" +
                "data1=" + data1 +
                ", data2=" + data2 +
                '}';
    }
}
public class Test {
    public static void main(String[] args) {
//        OutClass.InnerClass innerClass = new OutClass.InnerClass(new OutClass());
//        innerClass.test();
        OutClass outclass = new OutClass();
        System.out.println(outclass);
    }
    public static void main1(String[] args) {
//        OutClass out = new OutClass();
//        OutClass.InnerClass a = out.new InnerClass();
//        a.func();
    }
}
